<?php
@header("Content-Type:text/html;charset=utf-8");
$file = './label_count.txt'; //验证是否正在转换
if (is_file($file))
        exit('正在进行转换');
file_put_contents($file, '');
$startime = time();
set_time_limit(0);
include_once '../../nn_logic/nl_common.func.php';
include_once '../../nn_logic/label/video_label.class.php';
$dc = nl_get_dc(array(
    'db_policy' => NL_DB_WRITE,
    'cache_policy' => NP_KV_CACHE_TYPE_MEMCACHE
        )
);
$sql = "select nns_id,nns_type from nns_video_label WHERE `nns_count` >0";
$list = nl_query_by_db($sql, $dc->db());
$num = 0;
foreach ($list as $info) {
        if (empty($info['nns_type']))
                continue;
        $s = "select count(*) as count from nns_video_label_bind_{$info['nns_type']} where nns_label_id ='{$info['nns_id']}'";
        $count = nl_query_by_db($s, $dc->db());
        $count = $count[0];
        if (isset($count['count']) && is_numeric($count['count'])) {
                $up = "UPDATE `nn_mgtv`.`nns_video_label` SET `nns_count` = '{$count['count']}' WHERE `nns_id` = '{$info['nns_id']}'";
                $set = nl_execute_by_db($up, $dc->db());
                if ($set)
                        $num++;
        }
}
$txt = "总数:" . count($list) . "修改成功数目:" . $num;
echo $txt;
unlink($file);
?>